<?php
/**
* @package   auto_occasion
* @subpackage annonce
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/

/**
 * page d'ajout d'annonce en front
 * @ref ppt : AO _ Dépôt d_annonce(1)
 */
class FoAnnoncePaiementCtrl extends jController {

   /**
    * Paiement: 
    */
    function index() {
        $oResponse = $this->getResponse('htmlFo');

        jClasses::inc('annonce~annoncePaiementSrv');

        $oResponse->menusActifs = frontHtmlResponse::MENU_ANNONCE_GESTION ;
        $oResponse->breadCrumb  = array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_ANNONCE_GESTION) ;

        $oResponse->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/popup.js');
        $oResponse->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');

        $nb_min			= 1; 
        $nb_max			= 10000;
        $nombre_cmd		= rand($nb_min,$nb_max);

        $tarif			= annoncePaiementSrv::getTarif('5');
        $montant		= $tarif*100;
        $vendeur		= annoncePaiementSrv::getVendeur('378861');

        $pathregret		= 'http://' . $_SERVER['SERVER_NAME'] . jUrl::get('annonce~FoAnnoncePaiement:regret');
        $pathmerci		= 'http://' . $_SERVER['SERVER_NAME'] .  jUrl::get("annonce~FoAnnoncePaiement:merci", array('id'=>'378861'));

        $oResponse->bodyTpl	= 'annonce~FoAnnoncePaiement';
        $oResponse->body->assign('montant',round($montant));
        $oResponse->body->assign('tarif',$tarif);
        $oResponse->body->assign('nombre_cmd',$nombre_cmd);
        $oResponse->body->assign('vendeur',$vendeur);
        $oResponse->body->assign('pathregret',$pathregret);
        $oResponse->body->assign('pathmerci',$pathmerci);

        return $oResponse;
    }

    /**
    * Fonction permettant la validation lors de paiement réussi
    */
    function merci() {

        $id						= $this->intParam('id') ;
        $tarif					= $this->intParam('tarif') ;

        jClasses::inc('annonce~annoncePaiementSrv');
        jClasses::inc('publicite~pubSrv');
        jClasses::inc('commun~parametre');

        $pub1					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_1_ID);
        $pub2					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_2_ID);
        $pub3					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_3_ID);
        $pub4					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_4_ID);
        $pub5					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_5_ID);
        $pub6					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_6_ID); 
        $timeout				= parametre::get(PARAM_TIMEOUT_PUB);

        $oResponse				= $this->getResponse('htmlFo');
        $oResponse->menusActifs = frontHtmlResponse::MENU_ANNONCE_GESTION ;
        $oResponse->breadCrumb  = array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_ANNONCE_GESTION) ;

        $oResponse->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/popup.js');
        $oResponse->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');
        

       //mise à jour de correspondance entre annonce 
        //annoncePaiementSrv::majPaiement($id, $tarif);
        $oResponse->bodyTpl		= 'annonce~FoAnnoncePaiementMerci';
        $oResponse->body->assign('timeout', $timeout);
        $oResponse->body->assign('pub1', $pub1);
        $oResponse->body->assign('pub2', $pub2);
        $oResponse->body->assign('pub3', $pub3);
        $oResponse->body->assign('pub4', $pub4);
        $oResponse->body->assign('pub5', $pub5);
        $oResponse->body->assign('pub6', $pub6);
        $oResponse->body->assign('idOccasion', $id);

        return $oResponse;
    }

    /**
    * Fonction   de retour lors de paiement non effectué ou annulé
    */
    function regret() {

        jClasses::inc('annonce~annoncePaiementSrv');
        jClasses::inc('publicite~pubSrv');
        jClasses::inc('commun~parametre');

        $pub1					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_1_ID);
        $pub2					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_2_ID);
        $pub3					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_3_ID);
        $pub4					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_4_ID);
        $pub5					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_5_ID);
        $pub6					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_6_ID); 
        $timeout				= parametre::get(PARAM_TIMEOUT_PUB);

        $oResponse				= $this->getResponse('htmlFo');
        $oResponse->menusActifs	= frontHtmlResponse::MENU_ANNONCE_GESTION ;
        $oResponse->breadCrumb	= array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_ANNONCE_GESTION) ;

        $oResponse->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/popup.js');
        $oResponse->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');

        $oResponse->bodyTpl		= 'annonce~FoAnnoncePaiementRegret';
        $oResponse->body->assign('timeout', $timeout);
        $oResponse->body->assign('pub1', $pub1);
        $oResponse->body->assign('pub2', $pub2);
        $oResponse->body->assign('pub3', $pub3);
        $oResponse->body->assign('pub4', $pub4);
        $oResponse->body->assign('pub5', $pub5);
        $oResponse->body->assign('pub6', $pub6);
       
        return $oResponse;
    }


        /**
    * Fonction   de retour lors de paiement non effectué ou annulé
    */
    function notify() {

        jClasses::inc('annonce~annoncePaiementSrv');
        jClasses::inc('publicite~pubSrv');
        jClasses::inc('commun~parametre');

        $pub1					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_1_ID);
        $pub2					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_2_ID);
        $pub3					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_3_ID);
        $pub4					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_4_ID);
        $pub5					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_5_ID);
        $pub6					= pubSrv::getByRubriqueAndLocation(PUB_RUBRIQUE_HOME, PUB_RIGHT_6_ID); 
        $timeout				= parametre::get(PARAM_TIMEOUT_PUB);

        $oResponse				= $this->getResponse('htmlFo');
        $oResponse->menusActifs	= frontHtmlResponse::MENU_ANNONCE_GESTION ;
        $oResponse->breadCrumb	= array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_ANNONCE_GESTION) ;

        $oResponse->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/popup.js');
        $oResponse->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');


        $oResponse->bodyTpl		= 'annonce~FoAnnoncePaiementNotify';
        $oResponse->body->assign('timeout', $timeout);
        $oResponse->body->assign('pub1', $pub1);
        $oResponse->body->assign('pub2', $pub2);
        $oResponse->body->assign('pub3', $pub3);
        $oResponse->body->assign('pub4', $pub4);
        $oResponse->body->assign('pub5', $pub5);
        $oResponse->body->assign('pub6', $pub6);
       
        return $oResponse;
    }

}